package cn.aixuegao.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.swagger.annotations.Api;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 前后端开发交流文档配置类
 * @author hxy
 * @version 0.0.1
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {
	/**
	 * 一套API一个Bean
	 * @return
	 */
    @Bean
    public Docket testApi() {
        return new Docket(DocumentationType.SWAGGER_2)
        		.groupName("爱雪糕")  
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .paths(PathSelectors.any())
                .build();
    }
    
    /**
     * 可以针对上面的每套API定制不同的API信息、描述等
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Icey社区")
                .description("i雪糕系统开发前后端API交流文档 ------by 小天犬开发小组(HXY、CFL)")
                .termsOfServiceUrl("www.aixuegao.cn")
                .contact(new Contact("小天犬", "wwww.aixuegao.cn", "3143901851@qq.com"))
                .version("1.0.0").build();
    }
}
